package org.haredot.vo;

public class ResultVo<E> {

    private String status;

    private String message;

    private E data;

    public String getStatus() {
        return status;
    }

    public String getMessage() {
        return message;
    }

    public E getData() {
        return data;
    }

    public static <E> Builder<E> ok() {
        return new Builder<E>().status("10000");
    }

    public static <E> Builder<E> fail(String message) {
        return new Builder<E>().status("20000").message(message);
    }

    public static <E> Builder<E> asserts(boolean condition, String message) {
        Builder<E> builder = new Builder<>();
        if (condition) {
            builder.status("10000");
        } else {
            builder.status("20000").message(message);
        }
        return builder;
    }

    public static class Builder<E> {

        private final ResultVo<E> resultVo = new ResultVo<>();

        private Builder<E> status(String status) {
            resultVo.status = status;
            return this;
        }

        private Builder<E> message(String message) {
            resultVo.message = message;
            return this;
        }

        public Builder<E> data(E data) {
            resultVo.data = data;
            return this;
        }

        public ResultVo<E> build() {
            return resultVo;
        }

    }
}
